

cmake_minimum_required(VERSION 3.27)
SET(CMAKE_TOOLCHAIN_FILE "F:/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(boost_asio)
#
if(WIN32)
    message(STATUS "Compiling on a Windows platform")
    # Add Windows-specific settings or definitions here
    add_definitions(-D_WIN32_WINNT=0x0601)  # Replace with the minimum Windows version you are targeting, e.g., 0x0601 for Windows 7

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")

else()
    message(STATUS "Compiling on a non-Windows platform")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
    # Add non-Windows-specific settings or definitions here
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(asio CONFIG REQUIRED)
set(CMAKE_PREFIX_PATH "D:/Qt/6.5.3/mingw_64")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Threads REQUIRED)




find_package(Qt6 COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED)
add_executable(boost_asio main.cpp
        lib/mtcpserver.cpp
        lib/mtcpserver.h
        lib/msockettcp.cpp
        lib/msockettcp.h
        mwidget.cpp
        mwidget.h
        mwidget.ui
        lib/mserialport.cpp
        lib/mserialport.h
        lib/mport.cpp
        lib/mport.h
        mserialportq.cpp
        mserialportq.h
        lib/miodevicebase.cpp
        lib/miodevicebase.h)

target_link_libraries(boost_asio PRIVATE asio::asio)
target_link_libraries(boost_asio PRIVATE Threads::Threads)
if(WIN32)
    target_link_libraries(boost_asio PRIVATE ws2_32)
    target_link_libraries(boost_asio PRIVATE wsock32)
    target_link_libraries(boost_asio PRIVATE
            Qt::Core
            Qt::Gui
            Qt::Widgets
    )
endif()


if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    set(DEBUG_SUFFIX)
    if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
        set(DEBUG_SUFFIX "d")
    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
    endif ()
    foreach (QT_LIB Core Gui Widgets)
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt6${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
    endforeach (QT_LIB)
endif ()